#include <bits/stdc++.h>
#define int long long
#define N 400005
using namespace std;
int l[N], r[N], p[N], n, m, L, V;
int bit[N], b[N], aaa[N], top;
vector<int> ad[N], de[N];
bool mp[N], s[N];
void add(int x, int v) {
    while(x < N) bit[x] += v, x += x & -x;
}
int que(int x) {
    int res = 0;
    while(x) res += bit[x], x -= x & -x;
    return res;
}
int query(int l, int r) {
    if(l > r) return 0;
    return que(r)-que(l-1);
}
void work() {
    int ans1 = 0, ans2 = 0, tot = 0, cnt = 0;
    for(int i = 1; i <= 350000; i++) ad[i].clear(), de[i].clear();
    scanf("%lld%lld%lld%lld", &n, &m, &L, &V);
    for(int i = 1, d, v, a; i <= n; i++) {
        scanf("%lld%lld%lld", &d, &v, &a);
        double ll, rr;
        if(a == 0) ll = d, rr = (v > V ? L : d-1);
        else if(a > 0) ll = d+(V*V-v*v)*1.0/(2*a)+0.01, rr = L;
        else ll = d, rr = min(L*1.0, d-(v*v-V*V)*1.0/(2*a)-0.01);
        if(ll <= rr) {
            tot++, l[tot] = (int)(ll+0.5), r[tot] = (int)(rr);
            b[++cnt] = l[tot], b[++cnt] = r[tot];
        }
    }
    for(int i = 1; i <= m; i++) cin >> p[i], b[++cnt] = p[i];
    sort(b+1, b+cnt+1);
    cnt = unique(b+1, b+cnt+1)-(b+1);
    for(int i = 1; i <= tot; i++) {
        l[i] = lower_bound(b+1, b+cnt+1, l[i])-b;
        r[i] = lower_bound(b+1, b+cnt+1, r[i])-b;
    }
    for(int i = 1; i <= m; i++) {
        p[i] = lower_bound(b+1, b+cnt+1, p[i])-b;
        add(p[i], 1);
        s[p[i]] = 1;
    }
    for(int i = 1; i <= tot; i++) {
        mp[i] = 0;
        if(query(l[i], r[i])) {
            ans1++;
            ad[l[i]].push_back(i);
            de[r[i]].push_back(i);
        }
    }
    set<int> tmp;
    for(int i = 1, lsti; i <= 350000; i++) {
        if(s[i]) lsti = i;
        if(ad[i].size()) for(int x : ad[i]) tmp.insert(x);
        if(de[i].size()) {
            for(int x : de[i]) {
                if(!mp[x]) {
                    ans2++;
                    mp[x] = 1;
                    for(int y : tmp) if(l[y] <= lsti && lsti <= r[y]) mp[y] = 1, aaa[top++] = y;
                    for(int j = 0; j < top; j++) tmp.erase(aaa[j]);
                    top = 0;
                }
                tmp.erase(x);
            }
        }
    }
    for(int i = 1; i <= m; i++) add(p[i], -1), s[p[i]] = 0;
    printf("%lld %lld\n", ans1, m-ans2);
    return;
}
signed main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    scanf("%lld", &t);
    while(t--) work();
    return 0;
}
